package web;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo2")
public class ServletDemo2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取方式一：通过当前Servlet对象获取
        ServletContext servletContext3 = getServletContext();

        //获取方式二：通过Request请求对象获取
        ServletContext servletContext4 = req.getServletContext();

        System.out.println(servletContext3);
        System.out.println(servletContext4);
    }
}
